package light.head.dao.sys;


import java.io.InputStream;
import java.util.ArrayList;
import java.util.Date;
import java.util.Iterator;
import java.util.List;

import light.head.cache.Cache;
import light.head.config.Config;
import light.head.constant.Sys;
import light.head.framework.base.BaseDAO;
import light.head.framework.entity.Template;
import light.head.framework.utils.DateUtils;
import light.head.framework.utils.XmlUtils;
import light.head.model.Announcement;
import light.head.model.ApplyInfo;
import light.head.model.ApplyItem;
import light.head.model.LeaveManage;
import light.head.model.Reimburse;
import light.head.model.ReimburseItem;
import light.head.model.VehicleApply;
import light.head.model.VehicleApplyItem;

import org.dom4j.Document;
import org.dom4j.Element;
import org.springframework.stereotype.Service;

@Service
public class MessageTemplateDAO extends BaseDAO<Template, Integer> {
	private final static String SUBMITTER = "{[(submitter)]}";
	private final static String CREATETIME = "{[(createTime)]}";
	private final static String VERIFIER = "{[(verifier)]}";
	private final static String VERIFYTIME = "{[(verifytime)]}";
	private final static String TITLE = "{[(title)]}";
	private final static String LIST = "{[(list)]}";
	
	/* 邮件模块的编号ode*/
	private final static String MT_APPLY_CODE = "applyTemplate";
	private final static String AUDIT_TEMPLATE= "auditTemplate";
	private final static String AUDITS_TEMPLATE= "auditsTemplate";
	private final static String LEAVE_TEMPLATE= "leaveTemplate";
	private final static String REJECT_TEMPLATE = "rejectTemplate";
	private final static String REJECT_TEMPLATE2 = "rejectTemplate2";
	private final static String THROUGH_TEMPLATE = "throughTemplate";
	
	// 加载模版配置文件
	private final static String path = "/config/template.xml";
	
	private final static String CODE = "code";
	private final static String NAME = "name";
	private final static String CONTENT = "content";
	
	
	public List<Template> getAll() {
		if (null == Cache.templateList || Cache.templateList.size() == 0)
			loadAll();
		return Cache.templateList;
	}
	
	
	@SuppressWarnings("unchecked")
	public List<Template> loadAll() {
		Document xml = loadHandleXml();
		Element element = xml.getRootElement();

		if (null != element && element.elements().size() > 0) {
			List<Template> list = new ArrayList<Template>();
			Template tem = null;
			for (Iterator<Element> basicList = element.elementIterator();basicList.hasNext();) {
				Element basic = basicList.next();
				tem = new Template();
				for (Iterator<Element> sonList = basic.elementIterator();sonList.hasNext();) {
					Element son = sonList.next();
					if (null != son) {
						if(CODE.equals(son.getName()))
							tem.setCode(son.getText());
						if(NAME.equals(son.getName()))
							tem.setContent(son.getText());
						if(CONTENT.equals(son.getName()))
							tem.setName(son.getText());
					}
				}
				list.add(tem);
			}
			Cache.templateList = list;
			return list;
		}
		return null;
	}
	
	
	public static Document loadHandleXml() {
		InputStream in = Config.class.getResourceAsStream(path);
		Document xml = XmlUtils.loadXML(in);
		return xml;
	}
	
	
	
	// 通过CODE获取一条模版
	public Template getByCode(String code) {
		if (null == code || Sys.NONE.equals(code))
			return null;
		
		for (Template t : Cache.templateList) {
			if (code.equals(t.getCode())) {
				return t;
			}
		}
		
		return null;
	}
	
	// 物品申请
	
	/**
	 * 创建好物品申请信息后发消息通知一级审核人
	 * @author yy
	 * @Time 2013-11-15 下午7:14:00
	 * @param apply	申请信息
	 * @param submitter	提交人姓名
	 * @return	返回模板内容
	 */
	public String applyTofirst(ApplyInfo apply, String submitter) {
		
		if (null == apply) {
			return null;
		}
		Template mt =  getByCode(MT_APPLY_CODE);
		if (null == mt || !isNotNull(mt.getContent())) {
			return null;
		}
		
		String cnt = mt.getContent();
		
		if (cnt.indexOf(SUBMITTER) != -1) {
			cnt = cnt.replace(SUBMITTER, submitter);
		}
		if (cnt.indexOf(CREATETIME) != -1) {                                                                      
			cnt = cnt.replace(CREATETIME, DateUtils.getDateStr(apply.getAt(), "yyyy-MM-dd hh:mm:ss"));
		}
		if (cnt.indexOf(TITLE) != -1) {
			cnt = cnt.replace(TITLE, apply.getTitle());
		}
		if (cnt.indexOf(LIST) != -1) {
			StringBuffer str = new StringBuffer();
			for (ApplyItem item : apply.getAdList()) {
				str.append("商品名称：【" + item.getGn() + "】 数量:【" + item.getCount() + "】 <br />");
			}
			cnt = cnt.replace(LIST, str.toString());
		}
		return cnt;
	}

	/**
	 * 一级审核人审核成功后提交给二级审核人审核
	 * @author yy
	 * @param apply	申请信息
	 * @param submitter	提交人姓名
	 * @param verifier 审核人姓名
	 * @return	返回模板内容
	 */
	public String applyFirstToTwo(ApplyInfo apply, String submitter, String verifier, Date verifytime) {
		
		if (null == apply) {
			return null;
		}
		
		Template mt = getByCode(AUDIT_TEMPLATE);
		
		if (null == mt || !isNotNull(mt.getContent())) {
			return null;
		}
		
		String cnt = mt.getContent();
		
		if (cnt.indexOf(SUBMITTER) != -1) {
			cnt = cnt.replace(SUBMITTER, submitter);
		}
		if (cnt.indexOf(CREATETIME) != -1) {
			cnt = cnt.replace(CREATETIME, DateUtils.getDateStr(apply.getAt(), "yyyy-MM-dd hh:mm:ss"));
		}
		if (cnt.indexOf(VERIFIER) != -1) {
			cnt = cnt.replace(VERIFIER, verifier);
		}
		if (cnt.indexOf(VERIFYTIME ) != -1) {
			cnt = cnt.replace(VERIFYTIME, DateUtils.getDateStr(verifytime, "yyyy-MM-dd hh:mm:ss"));
		}
		if (cnt.indexOf(TITLE) != -1) {
			cnt = cnt.replace(TITLE, apply.getTitle());
		}
		if (cnt.indexOf(LIST) != -1) {
			StringBuffer str = new StringBuffer();
			for (ApplyItem item : apply.getAdList()) {
				str.append("商品名称：【" + item.getGn() + "】 数量:【" + item.getCount() + "】<br />");
			}
			cnt = cnt.replace(LIST, str.toString());
		}
		return cnt;
	}
	
	
	/**
	 * 审核人驳回申请提醒申请人
	 * @author yy
	 * @Time 2014-6-7 
	 * @param apply	申请信息
	 * @param verifier	审核人姓名
	 * @param verifytime 审核人时间 
	 * @param remark 驳回原因
	 * @return	返回模板内容
	 */
	public String rejectTofirst(ApplyInfo apply, String verifier,Date verifytime,String remark) {
		
		if (null == apply) {
			return null;
		}
		Template mt =  getByCode(REJECT_TEMPLATE);
		if (null == mt || !isNotNull(mt.getContent())) {
			return null;
		}
		String cnt = mt.getContent();
		
		if (cnt.indexOf(CREATETIME) != -1) {                                                                      
			cnt = cnt.replace(CREATETIME, DateUtils.getDateStr(apply.getAt(), "yyyy-MM-dd hh:mm:ss"));
		}
		if (cnt.indexOf(TITLE) != -1) {
			cnt = cnt.replace(TITLE, apply.getTitle());
		}
		if (cnt.indexOf(VERIFIER) != -1) {
			cnt = cnt.replace(VERIFIER, verifier);
		}
		if (cnt.indexOf(VERIFYTIME ) != -1) {
			cnt = cnt.replace(VERIFYTIME, DateUtils.getDateStr(verifytime, "yyyy-MM-dd hh:mm:ss"));
		}
		if (cnt.indexOf(LIST) != -1) {
			cnt = cnt.replace(LIST, remark);
		}
		return cnt;
	}
	
	
	/**
	 * 申请全部通过提醒申请人
	 * @author yy
	 * @Time 2014-6-7 
	 * @param time	申请时间
	 * @param verifytime 审核人时间 
	 * @return	返回模板内容
	 */
	public String throughToCu(Date time,Date verifytime) {
		
		Template mt =  getByCode(THROUGH_TEMPLATE);
		if (null == mt || !isNotNull(mt.getContent())) {
			return null;
		}
		String cnt = mt.getContent();
		if (cnt.indexOf(CREATETIME) != -1) {                                                                      
			cnt = cnt.replace(CREATETIME, DateUtils.getDateStr(time, "yyyy-MM-dd hh:mm:ss"));
		}
		if (cnt.indexOf(VERIFYTIME ) != -1) {
			cnt = cnt.replace(VERIFYTIME, DateUtils.getDateStr(verifytime, "yyyy-MM-dd hh:mm:ss"));
		}
		return cnt;
	}
	
	
	
// 请假申请
	/**
	 * 创建好请假申请信息后发消息通知审核人
	 * @author yy
	 * @Time 2014-6-6 
	 * @param apply	申请信息
	 * @param submitter	提交人姓名
	 * @return	返回模板内容
	 */
	public String leaverTofirst(LeaveManage le, String submitter) {
		
		if (null == le) return null;
		
		Template mt =  getByCode(LEAVE_TEMPLATE);
		if (null == mt || !isNotNull(mt.getContent())) {
			return null;
		}
		String cnt = mt.getContent();
		if (cnt.indexOf(SUBMITTER) != -1) {
			cnt = cnt.replace(SUBMITTER, submitter);
		}
		if (cnt.indexOf(CREATETIME) != -1) {                                                                      
			cnt = cnt.replace(CREATETIME, DateUtils.getDateStr(le.getCt(), "yyyy-MM-dd hh:mm:ss"));
		}
		if (cnt.indexOf(LIST) != -1) {
			StringBuffer str = new StringBuffer();
			str.append("请假时间从：【" + DateUtils.getDateStr(le.getSt(), "yyyy-MM-dd hh:mm:ss")+ "】 到:【" + DateUtils.getDateStr(le.getEt(), "yyyy-MM-dd hh:mm:ss") + "】<br />");
			cnt = cnt.replace(LIST, str.toString());
		}
		return cnt;
	}
	
	/**
	 * 审核人驳回申请提醒申请人
	 * @author yy
	 * @Time 2014-6-7 
	 * @param apply	申请信息
	 * @param verifier	审核人姓名
	 * @param verifytime 审核人时间 
	 * @param remark 驳回原因
	 * @return	返回模板内容
	 */
	public String rejectToSubmitter(LeaveManage leave, String verifier,Date verifytime,String remark) {
		
		if (null == leave) {
			return null;
		}
		Template mt =  getByCode(REJECT_TEMPLATE2);
		if (null == mt || !isNotNull(mt.getContent())) {
			return null;
		}
		String cnt = mt.getContent();
		
		if (cnt.indexOf(CREATETIME) != -1) {                                                                      
			cnt = cnt.replace(CREATETIME, DateUtils.getDateStr(leave.getCt(), "yyyy-MM-dd hh:mm:ss"));
		}
		if (cnt.indexOf(VERIFIER) != -1) {
			cnt = cnt.replace(VERIFIER, verifier);
		}
		if (cnt.indexOf(VERIFYTIME ) != -1) {
			cnt = cnt.replace(VERIFYTIME, DateUtils.getDateStr(verifytime, "yyyy-MM-dd hh:mm:ss"));
		}
		if (cnt.indexOf(LIST) != -1) {
			cnt = cnt.replace(LIST, remark);
		}
		return cnt;
	}
	
	
	/**
	 * 一级审核人审核成功后提交给二级审核人审核
	 * @author yy
	 * @param leave	申请信息
	 * @param submitter	提交人姓名
	 * @param verifier 审核人姓名
	 * @return	返回模板内容
	 */
	public String leaveFirstToTwo(LeaveManage le, String submitter, String verifier, Date verifytime) {
		
		if (null == le) {
			return null;
		}
		
		Template mt = getByCode(AUDITS_TEMPLATE);
		
		if (null == mt || !isNotNull(mt.getContent())) {
			return null;
		}
		
		String cnt = mt.getContent();
		
		if (cnt.indexOf(SUBMITTER) != -1) {
			cnt = cnt.replace(SUBMITTER, submitter);
		}
		if (cnt.indexOf(CREATETIME) != -1) {
			cnt = cnt.replace(CREATETIME, DateUtils.getDateStr(le.getCt(), "yyyy-MM-dd hh:mm:ss"));
		}
		if (cnt.indexOf(VERIFIER) != -1) {
			cnt = cnt.replace(VERIFIER, verifier);
		}
		if (cnt.indexOf(VERIFYTIME ) != -1) {
			cnt = cnt.replace(VERIFYTIME, DateUtils.getDateStr(verifytime, "yyyy-MM-dd hh:mm:ss"));
		}
		if (cnt.indexOf(LIST) != -1) {
			StringBuffer str = new StringBuffer();
			str.append("请假时间从：【" + DateUtils.getDateStr(le.getSt(), "yyyy-MM-dd hh:mm:ss")+ "】 到:【" + DateUtils.getDateStr(le.getEt(), "yyyy-MM-dd hh:mm:ss") + "】<br />");
			cnt = cnt.replace(LIST, str.toString());
		}
		return cnt;
	}
	
	// 用车申请
	/**
	 * 创建好物品申请信息后发消息通知一级审核人
	 * @author yy
	 * @Time 2013-11-15 下午7:14:00
	 * @param apply	申请信息
	 * @param submitter	提交人姓名
	 * @return	返回模板内容
	 */
	public String applyTofirst(VehicleApply apply, String submitter) {
		
		if (null == apply) {
			return null;
		}
		Template mt =  getByCode(MT_APPLY_CODE);
		if (null == mt || !isNotNull(mt.getContent())) {
			return null;
		}
		
		String cnt = mt.getContent();
		
		if (cnt.indexOf(SUBMITTER) != -1) {
			cnt = cnt.replace(SUBMITTER, submitter);
		}
		if (cnt.indexOf(CREATETIME) != -1) {                                                                      
			cnt = cnt.replace(CREATETIME, DateUtils.getDateStr(apply.getCt(), "yyyy-MM-dd hh:mm:ss"));
		}
		if (cnt.indexOf(TITLE) != -1) {
			cnt = cnt.replace(TITLE, apply.getTitle());
		}
		if (cnt.indexOf(LIST) != -1) {
			StringBuffer str = new StringBuffer();
			for (VehicleApplyItem item : apply.getAdList()) {
				str.append("名称：【" + item.getVtn() + "】 数量:【" + item.getCount() + "】 <br />");
			}
			cnt = cnt.replace(LIST, str.toString());
		}
		return cnt;
	}
	/**
	 * 一级审核人审核成功后提交给二级审核人审核
	 * @author yy
	 * @param apply	申请信息
	 * @param submitter	提交人姓名
	 * @param verifier 审核人姓名
	 * @return	返回模板内容
	 */
	public String applyFirstToTwo(VehicleApply apply, String submitter, String verifier, Date verifytime) {
		
		if (null == apply) {
			return null;
		}
		
		Template mt = getByCode(AUDIT_TEMPLATE);
		
		if (null == mt || !isNotNull(mt.getContent())) {
			return null;
		}
		
		String cnt = mt.getContent();
		
		if (cnt.indexOf(SUBMITTER) != -1) {
			cnt = cnt.replace(SUBMITTER, submitter);
		}
		if (cnt.indexOf(CREATETIME) != -1) {
			cnt = cnt.replace(CREATETIME, DateUtils.getDateStr(apply.getCt(), "yyyy-MM-dd hh:mm:ss"));
		}
		if (cnt.indexOf(VERIFIER) != -1) {
			cnt = cnt.replace(VERIFIER, verifier);
		}
		if (cnt.indexOf(VERIFYTIME ) != -1) {
			cnt = cnt.replace(VERIFYTIME, DateUtils.getDateStr(verifytime, "yyyy-MM-dd hh:mm:ss"));
		}
		if (cnt.indexOf(TITLE) != -1) {
			cnt = cnt.replace(TITLE, apply.getTitle());
		}
		if (cnt.indexOf(LIST) != -1) {
			StringBuffer str = new StringBuffer();
			for (VehicleApplyItem item : apply.getAdList()) {
				str.append("商品名称：【" + item.getVtn() + "】 数量:【" + item.getCount() + "】<br />");
			}
			cnt = cnt.replace(LIST, str.toString());
		}
		return cnt;
	}
	/**
	 * 审核人驳回申请提醒申请人
	 * @author yy
	 * @Time 2014-6-7 
	 * @param apply	申请信息
	 * @param verifier	审核人姓名
	 * @param verifytime 审核人时间 
	 * @param remark 驳回原因
	 * @return	返回模板内容
	 */
	public String rejectTofirst(VehicleApply apply, String verifier,Date verifytime,String remark) {
		
		if (null == apply) {
			return null;
		}
		Template mt =  getByCode(REJECT_TEMPLATE);
		if (null == mt || !isNotNull(mt.getContent())) {
			return null;
		}
		String cnt = mt.getContent();
		
		if (cnt.indexOf(CREATETIME) != -1) {                                                                      
			cnt = cnt.replace(CREATETIME, DateUtils.getDateStr(apply.getCt(), "yyyy-MM-dd hh:mm:ss"));
		}
		if (cnt.indexOf(TITLE) != -1) {
			cnt = cnt.replace(TITLE, apply.getTitle());
		}
		if (cnt.indexOf(VERIFIER) != -1) {
			cnt = cnt.replace(VERIFIER, verifier);
		}
		if (cnt.indexOf(VERIFYTIME ) != -1) {
			cnt = cnt.replace(VERIFYTIME, DateUtils.getDateStr(verifytime, "yyyy-MM-dd hh:mm:ss"));
		}
		if (cnt.indexOf(LIST) != -1) {
			cnt = cnt.replace(LIST, remark);
		}
		return cnt;
	}

	
	
	
	//报销流程
	/**
	 * 审核人驳回申请提醒申请人
	 * @author yy
	 * @Time 2014-6-7 
	 * @param apply	申请信息
	 * @param verifier	审核人姓名
	 * @param verifytime 审核人时间 
	 * @param remark 驳回原因
	 * @return	返回模板内容
	 */
	public String rejectTofirst(Reimburse re, String verifier,Date verifytime,String remark) {
		
		if (null == re) {
			return null;
		}
		Template mt =  getByCode(REJECT_TEMPLATE);
		if (null == mt || !isNotNull(mt.getContent())) {
			return null;
		}
		String cnt = mt.getContent();
		
		if (cnt.indexOf(CREATETIME) != -1) {                                                                      
			cnt = cnt.replace(CREATETIME, DateUtils.getDateStr(re.getCt(), "yyyy-MM-dd hh:mm:ss"));
		}
		if (cnt.indexOf(TITLE) != -1) {
			cnt = cnt.replace(TITLE, re.getTitle());
		}
		if (cnt.indexOf(VERIFIER) != -1) {
			cnt = cnt.replace(VERIFIER, verifier);
		}
		if (cnt.indexOf(VERIFYTIME ) != -1) {
			cnt = cnt.replace(VERIFYTIME, DateUtils.getDateStr(verifytime, "yyyy-MM-dd hh:mm:ss"));
		}
		if (cnt.indexOf(LIST) != -1) {
			cnt = cnt.replace(LIST, remark);
		}
		return cnt;
	}
	/**
	 * 一级审核人审核成功后提交给二级审核人审核
	 * @author yy
	 * @param apply	申请信息
	 * @param submitter	提交人姓名
	 * @param verifier 审核人姓名
	 * @return	返回模板内容
	 */
	public String applyFirstToTwo(Reimburse re, String submitter, String verifier, Date verifytime) {
		
		if (null == re) {
			return null;
		}
		
		Template mt = getByCode(AUDIT_TEMPLATE);
		
		if (null == mt || !isNotNull(mt.getContent())) {
			return null;
		}
		
		String cnt = mt.getContent();
		
		if (cnt.indexOf(SUBMITTER) != -1) {
			cnt = cnt.replace(SUBMITTER, submitter);
		}
		if (cnt.indexOf(CREATETIME) != -1) {
			cnt = cnt.replace(CREATETIME, DateUtils.getDateStr(re.getCt(), "yyyy-MM-dd hh:mm:ss"));
		}
		if (cnt.indexOf(VERIFIER) != -1) {
			cnt = cnt.replace(VERIFIER, verifier);
		}
		if (cnt.indexOf(VERIFYTIME ) != -1) {
			cnt = cnt.replace(VERIFYTIME, DateUtils.getDateStr(verifytime, "yyyy-MM-dd hh:mm:ss"));
		}
		if (cnt.indexOf(TITLE) != -1) {
			cnt = cnt.replace(TITLE, re.getTitle());
		}
		if (cnt.indexOf(LIST) != -1) {
			StringBuffer str = new StringBuffer();
			str.append("报销项目：");
			for (ReimburseItem item : re.getItemList()) {
				str.append("【" + item.getProject() + "】 数量:【" + item.getAmount() + "】<br />");
			}
			cnt = cnt.replace(LIST, str.toString());
		}
		return cnt;
	}
	/**
	 * 创建好物品申请信息后发消息通知一级审核人
	 * @author yy
	 * @Time 2013-11-15 下午7:14:00
	 * @param apply	申请信息
	 * @param submitter	提交人姓名
	 * @return	返回模板内容
	 */
	public String applyTofirst(Reimburse re, String submitter) {
		
		if (null == re) {
			return null;
		}
		Template mt =  getByCode(MT_APPLY_CODE);
		if (null == mt || !isNotNull(mt.getContent())) {
			return null;
		}
		
		String cnt = mt.getContent();
		
		if (cnt.indexOf(SUBMITTER) != -1) {
			cnt = cnt.replace(SUBMITTER, submitter);
		}
		if (cnt.indexOf(CREATETIME) != -1) {                                                                      
			cnt = cnt.replace(CREATETIME, DateUtils.getDateStr(re.getCt(), "yyyy-MM-dd"));
		}
		if (cnt.indexOf(TITLE) != -1) {
			cnt = cnt.replace(TITLE, re.getTitle());
		}
		if (cnt.indexOf(LIST) != -1) {
			StringBuffer str = new StringBuffer();
			str.append("报销项目：");
			for (ReimburseItem item : re.getItemList()) {
				str.append("【" + item.getProject() + "】 金额:【" + item.getAmount() + "】 <br />");
			}
			cnt = cnt.replace(LIST, str.toString());
		}
		return cnt;
	}
	
	
	//公告审核
	
	/**
	 * 创建好物品申请信息后发消息通知一级审核人
	 * @author yy
	 * @Time 2013-11-15 下午7:14:00
	 * @param apply	申请信息
	 * @param submitter	提交人姓名
	 * @return	返回模板内容
	 */
	public String applyTofirst(Announcement re, String submitter) {
		
		if (null == re) {
			return null;
		}
		Template mt =  getByCode("annTemplate");
		if (null == mt || !isNotNull(mt.getContent())) {
			return null;
		}
		
		String cnt = mt.getContent();
		
		if (cnt.indexOf(SUBMITTER) != -1) {
			cnt = cnt.replace(SUBMITTER, submitter);
		}
		if (cnt.indexOf(CREATETIME) != -1) {                                                                      
			cnt = cnt.replace(CREATETIME, DateUtils.getDateStr(re.getCt(), "yyyy-MM-dd hh:mm:ss"));
		}
		if (cnt.indexOf(TITLE) != -1) {
			cnt = cnt.replace(TITLE, re.getTitle());
		}
		return cnt;
	}
	
	/**
	 * 审核人驳回申请提醒申请人
	 * @author yy
	 * @Time 2014-6-7 
	 * @param apply	申请信息
	 * @param verifier	审核人姓名
	 * @param verifytime 审核人时间 
	 * @param remark 驳回原因
	 * @return	返回模板内容
	 */
	public String rejectTofirst(Announcement apply, String verifier,Date verifytime,String remark) {
		
		if (null == apply) {
			return null;
		}
		Template mt =  getByCode(REJECT_TEMPLATE);
		if (null == mt || !isNotNull(mt.getContent())) {
			return null;
		}
		String cnt = mt.getContent();
		
		if (cnt.indexOf(CREATETIME) != -1) {                                                                      
			cnt = cnt.replace(CREATETIME, DateUtils.getDateStr(apply.getCt(), "yyyy-MM-dd hh:mm:ss"));
		}
		if (cnt.indexOf(TITLE) != -1) {
			cnt = cnt.replace(TITLE, apply.getTitle());
		}
		if (cnt.indexOf(VERIFIER) != -1) {
			cnt = cnt.replace(VERIFIER, verifier);
		}
		if (cnt.indexOf(VERIFYTIME ) != -1) {
			cnt = cnt.replace(VERIFYTIME, DateUtils.getDateStr(verifytime, "yyyy-MM-dd hh:mm:ss"));
		}
		if (cnt.indexOf(LIST) != -1) {
			cnt = cnt.replace(LIST, remark);
		}
		return cnt;
	}
	// 物品申请
	
		/**
		 * 创建好物品申请信息后发消息通知一级审核人
		 * @author yy
		 * @Time 2013-11-15 下午7:14:00
		 * @param apply	申请信息
		 * @param submitter	提交人姓名
		 * @return	返回模板内容
		 */
		public String applyTofirst(Date time, String submitter) {
			
			Template mt =  getByCode(MT_APPLY_CODE);
			if (null == mt || !isNotNull(mt.getContent())) {
				return null;
			}
			String cnt = mt.getContent();
			
			if (cnt.indexOf(SUBMITTER) != -1) {
				cnt = cnt.replace(SUBMITTER, submitter);
			}
			if (cnt.indexOf(CREATETIME) != -1) {                                                                      
				cnt = cnt.replace(CREATETIME, DateUtils.getDateStr(time, "yyyy-MM-dd hh:mm:ss"));
			}
			return cnt;
		}
		
		/**
		 * 一级审核人审核成功后提交给二级审核人审核
		 * @author yy
		 * @param apply	申请信息
		 * @param submitter	提交人姓名
		 * @param verifier 审核人姓名
		 * @return	返回模板内容
		 */
		public String applyFirstToTwo(Date time, String submitter, String verifier, Date verifytime) {
			
			
			Template mt = getByCode(AUDIT_TEMPLATE);
			
			if (null == mt || !isNotNull(mt.getContent())) {
				return null;
			}
			
			String cnt = mt.getContent();
			
			if (cnt.indexOf(SUBMITTER) != -1) {
				cnt = cnt.replace(SUBMITTER, submitter);
			}
			if (cnt.indexOf(CREATETIME) != -1) {
				cnt = cnt.replace(CREATETIME, DateUtils.getDateStr(time, "yyyy-MM-dd hh:mm:ss"));
			}
			if (cnt.indexOf(VERIFIER) != -1) {
				cnt = cnt.replace(VERIFIER, verifier);
			}
			if (cnt.indexOf(VERIFYTIME ) != -1) {
				cnt = cnt.replace(VERIFYTIME, DateUtils.getDateStr(verifytime, "yyyy-MM-dd hh:mm:ss"));
			}
			return cnt;
		}
		
		/**
		 * 审核人驳回申请提醒申请人
		 * @author yy
		 * @Time 2014-6-7 
		 * @param apply	申请信息
		 * @param verifier	审核人姓名
		 * @param verifytime 审核人时间 
		 * @param remark 驳回原因
		 * @return	返回模板内容
		 */
		public String rejectTofirst(Date time, String verifier,Date verifytime,String remark) {
			
			Template mt =  getByCode(REJECT_TEMPLATE);
			if (null == mt || !isNotNull(mt.getContent())) {
				return null;
			}
			String cnt = mt.getContent();
			
			if (cnt.indexOf(CREATETIME) != -1) {                                                                      
				cnt = cnt.replace(CREATETIME, DateUtils.getDateStr(time, "yyyy-MM-dd hh:mm:ss"));
			}
			if (cnt.indexOf(VERIFIER) != -1) {
				cnt = cnt.replace(VERIFIER, verifier);
			}
			if (cnt.indexOf(VERIFYTIME ) != -1) {
				cnt = cnt.replace(VERIFYTIME, DateUtils.getDateStr(verifytime, "yyyy-MM-dd hh:mm:ss"));
			}
			if (cnt.indexOf(LIST) != -1) {
				cnt = cnt.replace(LIST, remark);
			}
			return cnt;
		}
		
}
